﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities.QuickSql;
using MySql.Data;

namespace Deviseur_Cs2i_Car
{
    public partial class AdminOption: Form
    {
        public AdminOption()
        {
            InitializeComponent();

            Thread OptionThread = new Thread(new ThreadStart(getAllOption_Thread));
            OptionThread.Start();
        }

        private void getAllOption_Thread()
        {
            Invoke(new MethodInvoker(getAllOption));
        }

        private void getAllOption()
        {
            Table option = Program.Db.QueryTable("SELECT O.NumOption, O.LibelleOption,O.PrixOption, C.LibelleCateg,S.NomSSOption FROM OPTIONS O LEFT OUTER JOIN CATEGOPTION C ON O.NumCateg = C.NumCateg LEFT OUTER JOIN SSOPTION S ON O.NumOption = S.NumOption");

            this.dataOption.Rows.Clear();

            foreach (Record r in option)
                this.dataOption.Rows.Add(r.Values[0], r.Values[1], r.Values[2], r.Values[3],r.Values[4]);
        }

        private void AdminOption_Activated(object sender, EventArgs e)
        {
            Thread OptionThread = new Thread(new ThreadStart(getAllOption_Thread));
            OptionThread.Start();
        }

        private void buttonAddOption_Click(object sender, EventArgs e)
        {
            AddOption FenAddoption = new AddOption();
            FenAddoption.ShowDialog();
        }

        private void AdminOption_Activated_1(object sender, EventArgs e)
        {
            Thread OptionThread = new Thread(new ThreadStart(getAllOption_Thread));
            OptionThread.Start();
        }

        private void buttonDelOption_Click(object sender, EventArgs e)
        {
            OPTION deloption = new OPTION();
            deloption.delete_Option(Convert.ToInt32(this.dataOption.SelectedRows[0].Cells[0].Value.ToString()));
            Thread TypeThread = new Thread(new ThreadStart(getAllOption_Thread));
            TypeThread.Start();
        }

        private void buttonDelOption_Click_1(object sender, EventArgs e)
        {
            OPTION deloption = new OPTION();
            deloption.delete_Option(Convert.ToInt32(this.dataOption.SelectedRows[0].Cells[0].Value.ToString()));
            Thread TypeThread = new Thread(new ThreadStart(getAllOption_Thread));
            TypeThread.Start();
        }

        private void buttonUpdateOption_Click(object sender, EventArgs e)
        {
            AddOption FenAddHTDI = new AddOption(Convert.ToInt32(this.dataOption.SelectedRows[0].Cells[0].Value.ToString()));
            FenAddHTDI.ShowDialog();
        }

    }
}
